package com.yy.yycompnent.slide
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;

	/**
	 *滚动条的slide 
	 * @author YY
	 * 
	 */
	public class ScrollSlider extends Slide
	{
		protected var _thumbPercent:Number = 1.0;//滑动条与滑动槽 的百分比
		protected var _pageSize:int = 1;//点击一次滚动的距离
		public function ScrollSlider(back:DisplayObject, handle:MovieClip, orientation:String=VERTICAL, defaultHandler:Function=null)
		{
			var sb:SliderBar = new SliderBar(handle);
			sb.showBar();
			super(back, sb, orientation, defaultHandler);
		}
		/**
		 * Initializes the component.
		 */
		protected override function init():void
		{
			super.init();
//			setSliderParams(1, 1, 0);
//			backClick = true;
		}
		
//		/**
//		 * Draws the handle of the slider.
//		 */
		override protected function drawHandle() : void
		{
			var size:Number;
			if(_orientation == HORIZONTAL)
			{
				size = Math.round(_back.width * _thumbPercent);
//				size = Math.max(_back.width, size);
				_handle.width = size;
			}
			else
			{
				size = Math.round(_back.height * _thumbPercent);
//				size = Math.max(_width, size);
				_handle.height = size;
			}
			positionHandle();
		}
//		
//		/**
//		 * Adjusts position of handle when value, maximum or minimum have changed.
//		 * TODO: Should also be called when slider is resized.
//		 */
//		protected override function positionHandle():void
//		{
////			var range:Number;
////			if(_orientation == HORIZONTAL)
////			{
////				range = width - _handle.width;
////				_handle.x = (_value - _min) / (_max - _min) * range;
////			}
////			else
////			{
////				range = height - _handle.height;
////				_handle.y = (_value - _min) / (_max - _min) * range;
////			}
//		}
//		
//		
//		
//		///////////////////////////////////
//		// public methods
//		///////////////////////////////////
//		
		/**
		 * Sets the percentage of the size of the thumb button.
		 */
		public function setThumbPercent(value:Number):void
		{
			_thumbPercent = Math.min(value, 1.0);
			draw();
		}
		
		/**
		 *隐藏显示 滚动条 
		 * 
		 */
		public function showBar(boo:Boolean=true):void {
			if(boo) {
				_handle.showBar();
			}else {
				_handle.hideBar();
			}
		}
		
		/**
		 *隐藏显示滑槽 
		 * @param boo
		 * 
		 */
		public function showBack(boo:Boolean=true):void {
			_back.visible = boo;
		} 
		
		/**
		 *隐藏显示滑动条 
		 * @param boo
		 * 
		 */
		public function show(boo:Boolean = true):void {
			showBar(boo);
			showBack(boo);
		}
//		
//		
//		
//		
//		
//		///////////////////////////////////
//		// event handlers
//		///////////////////////////////////
//		
////		/**
////		 * Handler called when user clicks the background of the slider, causing the handle to move to that point. Only active if backClick is true.
////		 * @param event The MouseEvent passed by the system.
////		 */
////		protected override function onBackClick(event:MouseEvent):void
////		{
////			if(_orientation == HORIZONTAL)
////			{
////				if(mouseX < _handle.x)
////				{
////					if(_max > _min)
////					{
////						_value -= _pageSize;
////					}
////					else
////					{
////						_value += _pageSize;
////					}
////					correctValue();
////				}
////				else
////				{
////					if(_max > _min)
////					{
////						_value += _pageSize;
////					}
////					else
////					{
////						_value -= _pageSize;
////					}
////					correctValue();
////				}
////				positionHandle();
////			}
////			else
////			{
////				if(mouseY < _handle.y)
////				{
////					if(_max > _min)
////					{
////						_value -= _pageSize;
////					}
////					else
////					{
////						_value += _pageSize;
////					}
////					correctValue();
////				}
////				else
////				{
////					if(_max > _min)
////					{
////						_value += _pageSize;
////					}
////					else
////					{
////						_value -= _pageSize;
////					}
////					correctValue();
////				}
////				positionHandle();
////			}
////			dispatchEvent(new Event(Event.CHANGE));
////			
////		}
//		
////		/**
////		 * Internal mouseDown handler. Starts dragging the handle.
////		 * @param event The MouseEvent passed by the system.
////		 */
////		protected override function onDrag(event:MouseEvent):void
////		{
////			stage.addEventListener(MouseEvent.MOUSE_UP, onDrop);
////			stage.addEventListener(MouseEvent.MOUSE_MOVE, onSlide);
////			if(_orientation == HORIZONTAL)
////			{
////				_handle.startDrag(false, new Rectangle(0, 0, _width - _handle.width, 0));
////			}
////			else
////			{
////				_handle.startDrag(false, new Rectangle(0, 0, 0, _height - _handle.height));
////			}
////		}
//		
//		/**
//		 * Internal mouseMove handler for when the handle is being moved.
//		 * @param event The MouseEvent passed by the system.
//		 */
////		protected override function onSlide(event:MouseEvent):void
////		{
////			var oldValue:Number = _value;
////			if(_orientation == HORIZONTAL)
////			{
////				if(_width == _handle.width)
////				{
////					_value = _min;
////				}
////				else
////				{
////					_value = _handle.x / (_width - _handle.width) * (_max - _min) + _min;
////				}
////			}
////			else
////			{
////				if(_height == _handle.height)
////				{
////					_value = _min;
////				}
////				else
////				{
////					_value = _handle.y / (_height - _handle.height) * (_max - _min) + _min;
////				}
////			}
////			if(_value != oldValue)
////			{
////				dispatchEvent(new Event(Event.CHANGE));
////			}
////		}
//		
//		
//		
//		
//		
//		///////////////////////////////////
//		// getter/setters
//		///////////////////////////////////
//		
		/**
		 * Sets / gets the amount the value will change when the back is clicked.
		 */
		public function set pageSize(value:int):void
		{
			_pageSize = value;
			draw();
		}
		public function get pageSize():int
		{
			return _pageSize;
		}
		
		public function get thumbPercent():Number
		{
			return _thumbPercent;
		}
	}
}
